package com.he.DesignPatterns.decorator.demo3_adater;

import java.lang.reflect.InvocationHandler;
import java.lang.reflect.Method;
import java.lang.reflect.Proxy;

/**
 * @description: JDK代理类
 * @Author: HCL
 * @Date: 2024/8/27 15:21
 */
public class ProxyClass {

    private QueryInterface queryInterface = new QueryInterfaceImpl();

    public QueryInterface getQueryInterface(){
        QueryInterface queryInterface1  = (QueryInterface) Proxy.newProxyInstance(
                queryInterface.getClass().getClassLoader(),
                queryInterface.getClass().getInterfaces(),
                new InvocationHandler() {
                    @Override
                    public Object invoke(Object proxy, Method method, Object[] args) throws Throwable {
                        Object object = method.invoke(queryInterface, args);
                        updateData();
                        return object;
                    }
                }
        );
        return queryInterface1;
    }

    public void updateData(){
        System.out.println("新增的更新操作_JDK动态代理");
    }
}
